package com.osi.Interceptor;

import cn.hutool.core.util.ObjectUtil;
import com.osi.bean.Logininfo;
import com.osi.utils.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {

    /**
     * 登录拦截器
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Logininfo logininfo = UserContext.getCurreentUser();
        if (ObjectUtil.isNotNull(logininfo)) {
            return true;
        } else {
            response.sendRedirect("/login");
            return false;
        }
    }
}
